<?php
if ($leave_record > 0) {
	$page = $this->uri->segment(4);
	$page = $page ? $page : 0;
	echo form_open();
	$this->load->view('incs/num_perpage');
	?>
	<table class="display" id="search">
		<thead>
			<tr class="success">
				<th>N&ordm;</th>
				<th>Staff Name</th>
				<th>Gender</th>
				<th>Type of Leave</th>
				<th>Reason</th>
				<th>Start Date</th>
				<th>End Date</th>
				<th>Duration</th>
				<th>Approved</th>
			</tr>
		</thead>
		<tbody>
			<?php
			// column id
			#echo $count;
			$id = 1;
			if ($this->uri->segment(4)) {
				$id = $this->uri->segment(4) + 1;
			} else {
				$id = 1;
			}
			foreach ($leave_record as $data):
				//duration of leaving think as Day
				$duration = $data->duration;
				if ($duration > 1) {
					$day = 'Days';
				} else {
					$day = 'day';
				}
				/* Display as Month	 * uss substr() to trim string for database of date */
				$str_date = substr($data->start_date, 6, -3);
				$months = array('January', 'February', 'Match', 'April', 'May', 'June', 'July', 'Auegst', 'September', 'October', 'November', 'December');
				for ($i = 0; $i < count($months); $i++) {
					if ($i == $str_date) {
						$month = $months[$i];
					}
				}
				?>

				<tr>
					<td class="center"><?php echo $id++; ?></td>
					<td class="center"><?php echo ucfirst($data->emp_fname) . ' ' . strtoupper($data->emp_lname); ?></td>
					<td class="center"><?php echo $data->emp_gender; ?></td>
					<td class="center"><?php echo $data->lea_name; ?></td>			

					<td class="center"><?php echo $data->lea_reason; ?></td>
					<td class="center"><?php echo $data->start_date; ?></td>
					<td class="center"><?php echo $data->end_date; ?></td>
					<td class="center"><?php echo $duration . nbs() . $day; ?></td>
					<?php
					$this->db->select("emp_lname,emp_fname");
					$this->db->from("pnc_employee");
					$this->db->where("staff_id", $data->val_id);
					$validator = $this->db->get();
					if ($validator->num_rows() > 0) {
						foreach ($validator->result() as $arr) {
							
						}
					}
					?>
					<td class="center">
						<?php
						echo img('bootstrap/images/tick.png', 'title="Approved"');
						?>
					</td>

				</tr>
				<?php
			endforeach;
			?></tbody>
	</table>
	<table>
		<tr>
			<td></td>
			<?php
			if ($pagination) {
				?>
				<td>
					<span class="pagination-link"><?php echo $pagination; ?></span>
				</td>
			</tr>
			<?php
		}
		?>

	</table>
	
	<?php
	
	echo form_close();
} else {
	?>
	<table>
		<tr>
			<td><?php echo "No Employee Request Leaving!!"; ?></td>
		</tr>
	</table>
<?php } ?>
